import 'package:flutter_oldman_health/models/response_data_model.dart';

class AlbumDataModel extends ResponseDataModel<List<AlbumModel>> {
  AlbumDataModel({int code, List<AlbumModel> data, String msg})
      : super(code: code, data: data, msg: msg);

  factory AlbumDataModel.fromJson(Map<String, dynamic> json) {
    var data = json["data"] as List;
    print(data);
    return AlbumDataModel(
        code: json["code"],
        data: data.map((e) => AlbumModel.fromJson(e)).toList(),
        msg: json['msg'] == "User has not logged in yet"
            ? "账户在其他设备登录"
            : json['msg']
    );
  }
}

class AlbumModel {
  String id;
  String name;
  String creator;
  int inDate;
  List<PhotoModel> photos;

  AlbumModel({this.id, this.name, this.creator, this.inDate, this.photos});

  factory AlbumModel.fromJson(Map<String, dynamic> json) {
    var list = json["photos"] as List;
    return AlbumModel(
        id: json["id"],
        name: json["name"],
        creator: json["creator"],
        inDate: json["inDate"],
        photos: list.map((e) => PhotoModel.fromJson(e)).toList());
  }

  bool myAlbum() {
    return "我" == creator;
  }
}
// @JsonSerializable()
class PhotoModel {
  String id;
  String name;
  String location;
  int inDate;

  PhotoModel({this.id, this.name, this.location, this.inDate});

// //flutter packages pub run build_runner build
//   factory PhotoModel.fromJson(Map<String, dynamic> json) =>_$ResultFromJson(json);
//
//   Map<String, dynamic> toJson()=>_$ResultFromJson(this);
  factory PhotoModel.fromJson(Map<String, dynamic> json) {
    return PhotoModel(
        id: json["id"],
        name: json["name"],
        location: json["location"],
        inDate: json["inDate"]);
  }
}
